#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <list>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_Release/NetEngine_Include/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_XStream/XStream_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_XStream/XStream_Error.h"

//g++ -std=gnu++11 -Wall -g Test_XPush.cpp -o Test_XPush -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_StreamMedia -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_Client -lNetEngine_BaseLib -lNetClient_Socket -lStreamMedia_XStream -Wl,-rpath=../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_Client:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_StreamMedia,--disable-new-dtags

int main()
{
    XNETHANDLE xhNet = 111;
    if (!XStream_ClientPush_Init(&xhNet, "127.0.0.1", 1931))
    {
        printf("XStream_ClientPush_Init %lX\n", XStream_GetLastError());
        return -1;
    }
    if (!XStream_ClientPush_PushHdr(xhNet))
    {
        printf("XStream_ClientPush_PushHdr %lX\n", XStream_GetLastError());
        return -1;
    }

    FILE* pSt_File = fopen("1080P.264", "rb");

    int i = 0;
    while (1)
    {
        TCHAR tszMsgBuffer[10240];
        memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
        int nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
        if (nRet <= 0)
        {
            break;
        }
        if (XStream_ClientPush_PushPkg(xhNet, tszMsgBuffer, nRet))
        {
            printf("%d==%d\n", nRet, i++);
        }
        int nSleepTime = 0;
        XStream_ClientPush_GetSpeed(xhNet, &nSleepTime);
        Sleep(nSleepTime);
    }
    XStream_ClientPush_Close(xhNet);
    return 0;
}
